package com.wnxy.sdd.front.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wnxy.sdd.front.entity.Course;
import com.wnxy.sdd.front.vo.CourseVo;
import com.wnxy.sdd.front.vo.IndexCourseQueryVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CourseMapper extends BaseMapper<Course> {
    /**
     * 新课上线
     */
    @Select("SELECT c.id,c.title,c.cover,c.view_count,c.price,COUNT(v.id) videoCount FROM sdd_course c \n" +
            "LEFT JOIN sdd_video v ON c.id=v.course_id\n" +
            "GROUP BY c.id,c.title,c.cover,c.view_count,c.price\n" +
            "ORDER BY c.update_time DESC LIMIT #{num}")
    List<IndexCourseQueryVo> queryNewCourse(int num);

//    @Select("select c.id, c.cover, c.title, c.view_count as viewCount, (select count(*) from sdd_video where course_id = c.id) videoCount " +
//            "from sdd_course c where c.status = 'Normal' order by c.buy_count desc")
    IPage<IndexCourseQueryVo> selectCoursePage(IPage<IndexCourseQueryVo> iPage,  @Param("subjectId") String subjectId);

    CourseVo queryCourseVoById(String id);

    List<CourseVo> findCourseByBuyCount(int i);
}
